home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / V15N04.ZIP / WARPCA.ZIP / WCABSRC.ZIP / FILEPROP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-18  |  3.1 KB  |  134 lines

  1. // DFilePropertiesDlg -- Class implementation
  2. #include <assert.h>
  3. #include <cstring.h>
  4. #include <classlib\arrays.h>
  5. #include <owl\owlpch.h>
  6. #include <owl\dialog.h>
  7. #include <owl\edit.h>
  8. #include <owl\static.h>
  9. #include <owl\button.h>
  10. #include "resource.h"
  11. #include "fileasoc.h"
  12. #include "filentry.h"
  13. #include "filetool.h"
  14. #include "fileprop.h"
  15.  
  16. #define DID_OK      1
  17. #define DID_CANCEL  2
  18.  
  19. DEFINE_RESPONSE_TABLE1(DFilePropertiesDlg, TDialog)
  20.     EV_CHILD_NOTIFY(DID_OK, BN_CLICKED, CmOk),
  21. END_RESPONSE_TABLE;
  22.  
  23. void DFilePropertiesDlg::SetupWindow()
  24. {
  25.     TDialog::SetupWindow();
  26.  
  27.     // Load first file's attributes to our property dialog.
  28.     FILEENTRY *pFileEntry;
  29.  
  30.     ULONG ulTotalBytes = 0;
  31.     ULONG ulTotalKiloBytes = 0;
  32.  
  33.     char szTemp[40];
  34.  
  35.     string strInfo("");
  36.     string strSize("");
  37.  
  38.     // On each click, update total dir.'s and files in status bar.
  39.     int nSelCount = SelectedFileList.GetItemsInContainer();
  40.  
  41.     for(int i = 0; i < nSelCount; i++)
  42.     {
  43.         pFileEntry = SelectedFileList[i];
  44.         // Total up our selected files.
  45.         if(pFileEntry)
  46.             ulTotalBytes += (ULONG)pFileEntry->lFileSize;
  47.     }
  48.  
  49.     pFileEntry = (FILEENTRY *)SelectedFileList[0];
  50.  
  51.     if(!pFileEntry)
  52.         return;
  53.  
  54.     if((pFileEntry->ulFileAttrib & FA_RDONLY) != 0)
  55.         CheckDlgButton(IDC_READONLY, 1);
  56.     if((pFileEntry->ulFileAttrib & FA_ARCH) != 0)
  57.         CheckDlgButton(IDC_ARCHIVE, 1);
  58.     if((pFileEntry->ulFileAttrib & FA_HIDDEN) != 0)
  59.         CheckDlgButton(IDC_HIDDEN, 1);
  60.     if((pFileEntry->ulFileAttrib & FA_SYSTEM) != 0)
  61.         CheckDlgButton(IDC_SYSTEM, 1);
  62.  
  63.     if(lpszCurrentDir)
  64.     {
  65.         strInfo = "Path: ";
  66.         strInfo += lpszCurrentDir;
  67.         SetDlgItemText(IDC_PATH, strInfo.c_str());
  68.     }
  69.  
  70.     ulTotalKiloBytes = ulTotalBytes / 1000;
  71.  
  72.     if(nSelCount == 1)
  73.     {
  74.         char szDateTime[30];
  75.  
  76.         GetFileTimeStampAsString(szDateTime, pFileEntry->uFileDate, pFileEntry->uFileTime);
  77.  
  78.         strInfo = "File: ";
  79.         strInfo += pFileEntry->szFileName;
  80.         SetDlgItemText(IDC_FILENAME, strInfo.c_str());
  81.  
  82.         strSize = "Size: ";
  83.         strSize += ltoa(ulTotalKiloBytes, szTemp, 10);
  84.         strSize += " KB";
  85.  
  86.         strInfo = "Modified: ";
  87.         strInfo += szDateTime;
  88.         SetDlgItemText(IDC_MODIFIED, strInfo.c_str());
  89.  
  90.         SetDlgItemText(IDC_FILESIZE, strSize.c_str());
  91.     }
  92.     else if(nSelCount > 1)
  93.     {
  94.         // Hide last modified.
  95.         WinShowWindow(GetDlgItem(IDC_MODIFIED), 0);
  96.  
  97.         // Hide filename, use size for both # of objects and total size.
  98.         WinShowWindow(GetDlgItem(IDC_FILENAME), 0);
  99.  
  100.         strInfo = itoa(nSelCount, szTemp, 10);
  101.         strInfo += " objects selected, ";
  102.  
  103.         strInfo += ltoa(ulTotalKiloBytes, szTemp, 10);
  104.         strInfo += " KB";
  105.  
  106.         SetDlgItemText(IDC_FILESIZE, strInfo.c_str());
  107.     }
  108. }
  109.  
  110. void DFilePropertiesDlg::CmOk()
  111. {
  112.     int rc;
  113.  
  114.     // Retrieve new attributes from buttons.
  115.     ULONG ulNewAttrib = 0;
  116.  
  117.     if(IsDlgButtonChecked(IDC_READONLY) == 1)
  118.         ulNewAttrib |= FA_RDONLY;
  119.     if(IsDlgButtonChecked(IDC_ARCHIVE) == 1)
  120.         ulNewAttrib |= FA_ARCH;
  121.     if(IsDlgButtonChecked(IDC_HIDDEN) == 1)
  122.         ulNewAttrib |= FA_HIDDEN;
  123.     if(IsDlgButtonChecked(IDC_SYSTEM) == 1)
  124.         ulNewAttrib |= FA_SYSTEM;
  125.  
  126.     rc = ChangeFileAttributes(lpszCurrentDir, ulNewAttrib);
  127.  
  128.     rc; // Kill warning.
  129.  
  130.     CloseWindow(TRUE);
  131. }
  132.  
  133.  
  134.